package servlet.task;

import bean.People;
import bean.Task;
import dao.TaskDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2017/6/26.
 */
@WebServlet(name = "UpdateTask", urlPatterns = "/updateTask")
public class UpdateTask extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setHeader("content-type", "text/html;charset=UTF-8");
        Task task = new Task();
        task.setId(Integer.parseInt(request.getParameter("taskId")));
        task.setName(request.getParameter("taskName"));
        task.setSummary(request.getParameter("taskSummary"));
        People people = new People();
        people.setId(Integer.parseInt(request.getParameter("peopleId")));
        task.setPeople(people);
        TaskDao taskDao = new TaskDao();
        int row = taskDao.updateTask(task);
        if (row != 0) {
            response.sendRedirect("/taskManager.jsp");
        } else {
            response.sendRedirect("/errorPage.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
